package org.nanhill.moo.domain;


/**
 * Flyweight factory
 * 
 * @time 2006-12-20
 * @author lin.wangl
 */
public class CostFactory {
	private final static CostFactory instance = new CostFactory();

	private Cost[] costs;


	private CostFactory() {
	}

	public static CostFactory instance() {
		return instance;
	}

	public void reset(Cost[] costs) {
		instance().costs = costs;

	}

	public Cost get(int id) {
		if (id < 1 || id > costs.length)
			return null;
		Cost cost = costs[id - 1];
		return cost;
	}

	public Cost getByName(String name) {
		for (Cost cost : costs)
			if (cost.getName().equals(name))
				return cost;
		return null;
	}

	public Cost[] getAll() {
		return costs;
	}

	public Cost getByEnName(String enName) {
		for (Cost cost : costs)
			if (cost.getEnName().equals(enName))
				return cost;
		return null;
	}

	/**
	 * @return
	 */
	public int getCount() {
		return costs.length;
	}

}
